package com.imedway.ihe.dtz.xds.service.impl;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.Addressing;
import javax.xml.ws.soap.SOAPBinding;

import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.lcm.SubmitObjectsRequest;
import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.query.AdhocQueryRequest;
import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.query.AdhocQueryResponse;
import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rs.RegistryResponseType;
import org.openehealth.ipf.commons.ihe.xds.iti18.Iti18PortType;
import org.openehealth.ipf.commons.ihe.xds.iti42.Iti42PortType;
import org.openehealth.ipf.commons.ihe.xds.iti61.Iti61PortType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.imedway.ihe.dtz.xds.registry.camel.Iti18Registry_CAMEL;
import com.imedway.ihe.dtz.xds.registry.camel.Iti42Registry_CAMEL;
import com.imedway.ihe.dtz.xds.registry.camel.Iti61Registry_CAMEL;
import com.imedway.ihe.dtz.xds.service.XdsRegistryService;
import com.imedway.ihe.dtz.xds.util.JaxbMapperUtils;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@WebService
@Service
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
@Addressing(required = true)
public class XdsRegistry implements XdsRegistryService{

	
	@Autowired
	private Iti18Registry_CAMEL iti18Registry_CAMEL;
	
	@Autowired
	private Iti42Registry_CAMEL iti42Registry_CAMEL;
	
	@Autowired
	private Iti61Registry_CAMEL iti61Registry_CAMEL;
	
	@WebMethod
	@Override
	public AdhocQueryResponse documentRegistryRegistryStoredQuery(AdhocQueryRequest body) {
		log.info(JaxbMapperUtils.convertToXml(body, "UTF-8", true));
		AdhocQueryResponse adhocQueryResponse=new AdhocQueryResponse();
//		Iti18Registry iti18Registry = new Iti18Registry();
//		adhocQueryResponse=iti18Registry.run(body);
		adhocQueryResponse=iti18Registry_CAMEL.run(body);
		log.info(JaxbMapperUtils.convertToXml(adhocQueryResponse, "UTF-8", true));
		return adhocQueryResponse;
	}
	
    @WebMethod
    @Override
    public RegistryResponseType documentRegistryRegisterDocumentSetB(SubmitObjectsRequest body) {
    	
		log.info(JaxbMapperUtils.convertToXml(body, "UTF-8", true));
		RegistryResponseType registryResponseType = new RegistryResponseType();
//		registryResponseType = iIti42Registry.run(body);	
		registryResponseType = iti42Registry_CAMEL.run(body);	
		log.info(JaxbMapperUtils.convertToXml(registryResponseType, "UTF-8", true));
		return registryResponseType;

    }
    
    @WebMethod
    @Override
    public RegistryResponseType documentRegistryRegisterOnDemandDocumentEntry(SubmitObjectsRequest body) {
    	
    	log.info(JaxbMapperUtils.convertToXml(body, "UTF-8", true));
		RegistryResponseType registryResponseType = new RegistryResponseType();
//		registryResponseType = iIti61Registry.run(body);
		registryResponseType = iti61Registry_CAMEL.run(body);

		return registryResponseType;   	
    }

}
